package cn.jinhe.doc.view.action;

import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import cn.jinhe.doc.base.BaseAction;
import cn.jinhe.doc.domain.MaterialType;
import cn.jinhe.doc.domain.PcInfo;
import cn.jinhe.doc.util.QueryHelper;

@Controller
@Scope("prototype")
public class MaterialTypeAction extends BaseAction<MaterialType>{
	public String list() throws Exception {
		//List<User> userList = userService.findAll();
		//ActionContext.getContext().put("userList", userList);
		
		//准备分页信息
		new QueryHelper(MaterialType.class, "m").preparePageBean(materialTypeService, pageNum, pageSize);
		
		return "list";
	}
	/*
	 * 删除
	 */
	public String delete() throws Exception {
		materialTypeService.delete(model.getId());
		return "toList";
	}

	/*
	 * 添加
	 */
	public String add() throws Exception {
		
/*		model.setDepartment(departmentService.getById(departmentId));
		List<Role> roleList=roleService.getByIds(roleIds);
		model.setRoles(new HashSet<Role>(roleList));
//		model.setRoles(new ArrayList().addAll(roleList));
		
		String md5Digest=DigestUtils.md5Hex("1234");
		model.setPassword(md5Digest);*/
//		model.setStore((long) 0);
		materialTypeService.save(model);

		return "toList";
	}

	/*
	 * 添加页面
	 */
	public String addUI() throws Exception {
		List<MaterialType> materialTypeList=materialTypeService.findAll();
		
		ActionContext.getContext().put("materialTypeList", materialTypeList);
		return "saveUI";	
	}

	/*
	 * 修改页面
	 */
	public String editUI() throws Exception {
		
		MaterialType materialType=materialTypeService.getById(model.getId());
		ActionContext.getContext().getValueStack().push(materialType);
		return "saveUI";
	}

	/*
	 * 修改
	 */
	public String edit() throws Exception {
		//1,从数据库中取出原对象
		MaterialType materialType=materialTypeService.getById(model.getId());
		
		//2，设置要修改的属性
	
		materialType.setType(model.getType());
		materialType.setDescription(model.getDescription());
		materialTypeService.update(materialType);
		
		return "toList";
	}
}
